<?php

/**
 * LoginForm class.
 * LoginForm is the data structure for keeping
 * user login form data. It is used by the 'login' action of 'SiteController'.
 */
class FindPasswordForm extends CFormModel {

    public $email;
    public $verifyCode;

    /**
     * Declares the validation rules.
     * The rules state that username and password are required,
     * and password needs to be authenticated.
     */
    public function rules() {
        return array(
            array('email', 'required', 'message' => '邮箱不能为空！'),
            array('email', 'email', 'message' => '您输入的邮件地址无效！'),
            array('email', 'emailIsReg'),
            array('verifyCode', 'captcha'),
        );
    }

    /**
     * Declares attribute labels.
     */
    public function attributeLabels() {
        return array(
            'email' => '注册邮箱',
            'verifyCode' => '验证码',
        );
    }

    /**
     * Authenticates the password.
     * This is the 'authenticate' validator as declared in rules().
     */
    public function emailIsReg($attribute, $params) {
        $user = MembersModel::model()->find('email =  ?', array($this->email));
        if (!$user) {
            $this->addError('email', '您输入的邮箱未注册！.');
        }
    }

}
